<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<head>
    <meta charset="UTF-8">
    <title>评论管理 - 企业培训平台</title>
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <style>
        .comment-card { border: 1px solid #ddd; border-radius: 8px; margin-bottom: 20px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
        .comment-header { background-color: #f8f9fa; padding: 10px 15px; border-bottom: 1px solid #ddd; }
        .comment-body { padding: 15px; }
        .student-comment { margin-bottom: 15px; }
        .teacher-reply { background-color: #e9f7ef; padding: 10px; border-radius: 5px; margin-top: 10px; border-left: 3px solid #28a745;}
        .reply-form textarea { width: 100%; min-height: 80px; margin-top: 10px; }
    </style>
</head>
<body>
<div th:replace="~{fragments/header :: header}"></div>
<div class="main-content">
    <div class="container">
        <h1 class="page-title">评论管理</h1>
        <p>在这里管理您所有课程收到的学生评论，并进行回复。</p>

        <div th:if="${successMessage}" class="alert alert-success" th:text="${successMessage}"></div>
        <div th:if="${errorMessage}" class="alert alert-danger" th:text="${errorMessage}"></div>

        <div th:if="${#lists.isEmpty(comments)}">
            <p>您的课程暂无任何评论。</p>
        </div>

        <div th:each="comment : ${comments}" class="comment-card">
            <div class="comment-header">
                <strong>课程:</strong> <span th:text="${comment.courseName}"></span> |
                <strong>学生:</strong> <span th:text="${comment.studentName}"></span> |
                <strong>评分:</strong> <span th:text="${comment.rating} + ' / 5'"></span> |
                <strong>时间:</strong> <span th:text="${#temporals.format(comment.createTime, 'yyyy-MM-dd HH:mm')}"></span>
            </div>
            <div class="comment-body">
                <div class="student-comment">
                    <p><strong>评论内容:</strong></p>
                    <p th:text="${comment.content}"></p>
                </div>

                <div th:if="${comment.reply != null}" class="teacher-reply">
                    <p><strong>您的回复:</strong></p>
                    <p th:text="${comment.reply.content}"></p>
                    <small>回复于: <span th:text="${#temporals.format(comment.reply.createTime, 'yyyy-MM-dd HH:mm')}"></span></small>
                </div>

                <div th:if="${comment.reply == null}">
                    <form th:action="@{/teacher/comments/reply}" method="post" class="reply-form">
                        <input type="hidden" name="commentId" th:value="${comment.commentId}" />
                        <textarea name="content" placeholder="输入您的回复..." required></textarea>
                        <button type="submit" class="btn btn-primary btn-sm" style="margin-top: 5px;">提交回复</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>